package org.example.types.design.framework.tree;

import lombok.Getter;
import lombok.Setter;

public abstract class AbstractMultiThreadStrategyRouter<T,D,R> implements StrategyHandle<T,D,R>,StrategyMapper<T,D,R>{
    @Getter
    @Setter
    protected  StrategyHandle<T,D,R> defaultStrategyHandler=StrategyHandle.DEFAULT;

    public R router(T requestParameter,D dynamicContext) throws Exception{

        StrategyHandle<T,D,R> strategyHandle=get(requestParameter,dynamicContext);
        if(null!=strategyHandle) return strategyHandle.apply(requestParameter, dynamicContext);
        return defaultStrategyHandler.apply(requestParameter, dynamicContext);
    }

    @Override
    public R apply(T requestParameter, D dynamicContext) throws Exception {
        mutiThread(requestParameter,dynamicContext);
        return doApply(requestParameter,dynamicContext);
    }

    protected abstract R doApply(T requestParameter, D dynamicContext) throws Exception;

    protected abstract void mutiThread(T requestParameter, D dynamicContext) throws Exception;

}
